{% extends 'basic/layout.html' %}

{% block extrahead %}
{{ super() }}
{% if domain == 'scipy-lectures.org' %}
  {% if pagename.endswith('index') %}
  <meta http-equiv="refresh" content="0; url=https://lectures.scientific-python.org/{{ pagename.rsplit('/', 1)[0] }}"}}>
  {% else %}
  <meta http-equiv="refresh" content="0; url=https://lectures.scientific-python.org/{{ pagename }}.html"}}>
  {% endif %}
{% endif %}
<script defer data-domain="lectures.scientific-python.org" src="https://views.scientific-python.org/js/script.js"></script>
{% endblock %}

{% block sidebarsourcelink %}
{% endblock %}

{% block sidebarrel %}
{% endblock %}

{% block sidebartoc %}
    {%- if (pathto('index') != '#') %}
        <div class="sidebartoc">{{ super() }}</div>
    {%- endif %}
{% endblock %}

{%- block sidebarsearch %}
    <div class="script_container">
    <script>
    (function() {
        var cx = '004523248466141510607:hgv2yimrahw';
        var gcse = document.createElement('script');
        gcse.type = 'text/javascript';
        gcse.async = true;
        gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
            '//cse.google.com/cse.js?cx=' + cx;
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(gcse, s);
    })();
    </script>
    <gcse:search></gcse:search>
    </div>
    {%- if (pathto('index') == '#') %}
        <img class="sidebarlogo" src="_images/logo.svg"/>
    {%- endif %}
{% endblock %}


{% block relbaritems %}
    {{ super() }}
    <!-- Insert a tip toggle in the navigation bar -->
        <li class="left">
        <!-- On click, expand all tips -->
        <!--
        <a>
            <img src="{{ pathto('_static/plus.png', 1) }}"
                 alt="Expand tips" style="padding: 1ex;"/>
            <span class="hiddenlink">Collapse document to compact view</span>
        </a>
        -->
        </li>
    <li class="right edit_on_github"><a href="https://github.com/scipy-lectures/scientific-python-lectures/edit/main/{{ pagename }}.rst">Edit
      <span class="tooltip">
        Improve this page:<br/>Edit it on Github.
      </span>
    </a>
    </li>
    {% endblock %}

    {% block header %}
    <!-- Use the header to add javascript -->
    {{ super() }}

    <script type="text/javascript">
     // Function to toggle tip div
     function toggle_tip_div(obj) {
       $(obj).find("p.summary").remove();

       var content = $(obj).text();
       var html = $(obj).html();

       if ($(obj).hasClass("collapsed")) {
         // Expand
         $(obj).html('<p class="summary"><img src="{{ pathto('_static/minus.png', 1) }}"></p>' + html);
       } else {
         // Collapse
         if(content.length > 50) {
           content = content.substr(0, 47);
         }
         $(obj).html('<p class="summary"><img src="{{ pathto('_static/plus.png', 1) }}">' + content + '...</p>' + html);
       }

       $(obj).toggleClass("collapsed");
     }

     $(document).ready(function () {
       $(".tip").each(function() {
         $(this).find("p.admonition-title").remove();
       });
       // Collapse all tips and add plus sign
       $(".tip").each(function() { toggle_tip_div($(this)); });

       $(".tip")
         .click(function(event){
           // Change state of the global button
           $('div.related li.transparent').removeClass('transparent');
           toggle_tip_div($(this));
           if (event.target.tagName.toLowerCase() != "a") {
             return true; //Makes links clickable
           }
         });
     });
    </script>

{% endblock %}
